package com.hcss.common.util;

import java.io.File;

import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncodingAttributes;

//https://blog.csdn.net/bestcxx/article/details/51895839
public class AmrToMp3 {
	
	public static String changeToMp3(String sourcePath) {
		File source = new File(sourcePath);
		String targetPath = sourcePath.substring(0, sourcePath.lastIndexOf(".") + 1) + "mp3";
		File target = new File(targetPath);
		AudioAttributes audio = new AudioAttributes();
		Encoder encoder = new Encoder();

		audio.setCodec("libmp3lame");
		EncodingAttributes attrs = new EncodingAttributes();
		attrs.setFormat("mp3");
		attrs.setAudioAttributes(audio);
		try {
			encoder.encode(source, target, attrs);
		}catch(Exception e) {
		}
		return targetPath;
	}

}
